//
//  MyDocument.m
//  iBioCAD
//
//  Created by Orbitus on 9/12/07.
//  Copyright __MyCompanyName__ 2007 . All rights reserved.
//

#import "MyDocument.h"

@implementation MyDocument

- (void)setSpeedDNATextView:(int)a
{
	NSLog(@"SpeedDNA text View!");
	[ticksField setIntValue:a];
	//[speedView setNCUTextView:a];
	//[speedView setNeedsDisplay:YES];
}

- (id)init 
{
    self = [super init];
    NSMOCDidChangeNotification = [NSNotification notificationWithName:@"NSMOCDidChangeNotification" object:nil];

	if (self != nil) {
		[[NSNotificationCenter defaultCenter]
		 addObserver:self selector:@selector(updateView:) name:@"NSMOCDidChangeNotification" object:nil];

		managedObjectModel = [self managedObjectModel];
		managedObjectContext = [self managedObjectContext];
		
		
		
		/*
		entities = [managedObjectModel entitiesByName];
		
		dnaEntity = [entities valueForKey:@"DNA"];
		dnaSort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
		dnaSortDescriptors = [NSArray arrayWithObject: dnaSort];
		dnaFetch = [[NSFetchRequest alloc] init];
		[dnaFetch setEntity: dnaEntity];
		[dnaFetch setSortDescriptors: dnaSortDescriptors];
		*/
		
		
    }
    return self;
}

- (void) updateView:(id)b
{
	NSLog(@"MOC DID CHANGE NOTIFICATION");
		//[dnaView setString: [[[DNAArrayController selectedObjects] objectAtIndex:0] valueForKey:@"sequence"]];
	//Fetch your own DNA string
	//[dnaView setString: @"ATGTGTGATTAAGTAGTCTCCATCGTACGCGGCGGCGGCGCATTGCATCGCTTTTTTTTTTTTTTTTTTTTTT"];

}

- (NSString *)windowNibName 
{
    return @"MyDocument";
}
- (id)dnaArrayController{
	return dnaArrayController;
}
- (id)atomArrayController{
	return atomArrayController;
}
- (id)proteinArrayController{
	return proteinArrayController;
}
- (void)windowControllerDidLoadNib:(NSWindowController *)windowController 
{
    [super windowControllerDidLoadNib:windowController];
    // user interface preparation code
	
	NSString *path = [@"~/Pictures/All Desktop Pictures" stringByExpandingTildeInPath];
    BOOL isDirectory = NO;
    BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory];
    if (exists && isDirectory) {
        [myMainController openBrowserWindowForPath:path];
    } else {
        [myMainController browseNatureDesktopPictures:self];
    }
	
}

- (void)reportIn:(id)a
{
	NSLog(@"Reporting In");
}

- (IBAction) changeSize:(id)sender
{
	NSLog(@"Size is changing");
	//[myGLView frame].size.height;
	//[myGLView setFrame:NSMakeRect( [myGLView frame].origin.x-45,[myGLView frame].origin.y, [myGLView frame].size.width, [myGLView frame].size.height)];
	
	
}
- (void) doIT:(id)valuesArray
{
	
	[speedField setValue:[valuesArray objectAtIndex:0]];
	[ticksField setValue:[valuesArray objectAtIndex:1]];
	[curveField setValue:[valuesArray objectAtIndex:2]];
	NSLog(@"Applying");
	[self applySpeedometerSettings:self];

}

- (IBAction)applySpeedometerSettings:(id)sender {
	//NSLog(@"Message to APPLY recieved");
	
	[NSAnimationContext beginGrouping];									//	Grouping the animations forces them all to start at the same time
	
	[[NSAnimationContext currentContext] setDuration:[durationField doubleValue]];	//	Set the duration of the animation. Default is 1/4 second
	[[myGLView animator] setFly:[curveField floatValue]];
	[[speedView animator] setSpeed:[speedField floatValue]];			//	Set the speed needle
	[[speedView animator] setTicks:[ticksField floatValue]];			//	Number of ticks to draw on the speedometer
	[[speedView animator] setCurvature:[curveField floatValue]];		//	The % curvature of our custom speedometer
	
	[NSAnimationContext endGrouping];									//	Grouped animations start here
}
@end
